const {
    controller,
    get,
    post,
    put
} = require('../lib/decorator')
const {
    checkPassword
} = require('../service/user')

// router 中也可以运行两个中间件，通过 return next() 传递
@controller('/admin')
export class userController {
    @post('/login')
    async login(ctx, next) {
        console.log('body:',ctx.request.body)
        const { email, password } = ctx.request.body
        const matchData = await checkPassword(email, password)
        /* console.log('emain', email)
        console.log('password', password)
        console.log('matchData',matchData) */
        if (!matchData.user) {
            return (ctx.body = {
                success: false,
                err: '用户不存在'
            })
        }
        if (matchData.match) {
            return (ctx.body = {
                success: true
            })
        }

        return (ctx.body = {
            success: false,
            err: '密码不正确'
        })
    }
}